<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no" />
  <title>首页</title>
  <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
</head>

<body>
  <div id="canvas-wrp">
    <canvas id="canvas" style=" border:1px solid #ccc ;display: block; margin: 100px auto;"></canvas>

  </div>
</body>

<script>
  let canvas = document.querySelector('#canvas')
  canvas.width = 800
  canvas.height = 600
  let ctx = canvas.getContext("2d");

  ctx.beginPath()// 开始一条路径或是重置当前路径
  ctx.moveTo(100, 100)
  ctx.lineTo(300, 300)
  ctx.lineTo(100, 500)
  ctx.lineWidth = 5
  ctx.strokeStyle = 'red'
  ctx.stroke()

  ctx.beginPath()
  ctx.moveTo(300, 100)
  ctx.lineTo(500, 300)
  ctx.lineTo(300, 500)
  ctx.lineWidth = 5
  ctx.strokeStyle = 'pink'
  ctx.stroke() //方法会实际地绘制出通过 moveTo() 和 lineTo() 方法定义的路径

  ctx.beginPath()
  ctx.moveTo(500, 100)
  ctx.lineTo(700, 300)
  ctx.lineTo(500, 500);
  ctx.lineWidth = 5
  ctx.strokeStyle = 'blue'
  ctx.stroke()
</script>

</html>